package dmp.llapi.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UrlParseList {
	
	private static final String FILE_NAME = "rule.txt";

	private static List<String> url_parse_param = new ArrayList<String>();
	
	static {
//		BufferedReader br = new BufferedReader(new InputStreamReader(DomainList.class.getResourceAsStream("/domainlist.txt")));
		File file = new File(System.getProperty("user.dir") + "/" + FILE_NAME);
		if (file.exists()) {
			BufferedReader br = null;
			try {
				br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
				String line = null;
				while ((line = br.readLine()) != null) {
					url_parse_param.add(line);
				}
				
				
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (br != null) {
					try {
						br.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
	
	public static List<String> elements() {
		return url_parse_param;
	}
	
	public static Map<String, String> getParserMap(){
		Map<String, String> map=new HashMap<>();
		
		List<String> es = UrlParseList.elements();
		for (String each : es) {
			String name=each.split("\\|")[0];
			map.put(name, each);
		}
		return map;
	}
	
}
